package org.zuel.huhuForum.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.zuel.huhuForum.controller.interceptor.LoginTicketInterceptor;
import org.zuel.huhuForum.controller.interceptor.MessageInterceptor;
import org.zuel.huhuForum.controller.interceptor.PowerInterceptor;
import org.zuel.huhuForum.controller.interceptor.WebCorsFilter;

import java.util.HashMap;
import java.util.Map;

@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
    @Autowired
    private LoginTicketInterceptor loginTicketInterceptor;

    @Autowired
    private MessageInterceptor messageInterceptor;

    @Autowired
    private WebCorsFilter webCorsFilter;

    @Autowired
    private PowerInterceptor powerInterceptor;
//    /**
//     * 跨域访问配置
//     */
//    @Override
//    public void addCorsMappings(CorsRegistry registry) {
//        registry.addMapping("/**")
//                .allowedOrigins("*")
//                .allowedMethods("GET", "POST", "OPTIONS", "PUT")
//                .allowedHeaders("Content-Type", "X-Requested-With", "accept", "Origin", "Access-Control-Request-Method", "Access-Control-Request-Headers")
//                .exposedHeaders("Access-Control-Allow-Origin", "Access-Control-Allow-Credentials")
//                .allowCredentials(true)
//                .maxAge(3600);
//    }

    // 对除静态资源外所有路径进行拦截
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
//        registry.addInterceptor(webCorsFilter)
//                .excludePathPatterns("/css/**", "/js/**", "swagger-ui.html","/img/**", "/editor-md/**", "/editor-md-upload/**");

//        registry.addInterceptor(loginTicketInterceptor)
//                .excludePathPatterns("/css/**", "/js/**", "swagger-ui.html","/img/**", "/editor-md/**", "/editor-md-upload/**");


//        registry.addInterceptor(powerInterceptor)
//                .excludePathPatterns("/css/**", "/js/**", "swagger-ui.html","/img/**", "/editor-md/**", "/editor-md-upload/**");

        registry.addInterceptor(messageInterceptor)
                .excludePathPatterns("/css/**", "/js/**", "swagger-ui.html","/img/**", "/editor-md/**", "/editor-md-upload/**");

    }


}
